package com.jewelry.entity;

import lombok.Data;
import org.w3c.dom.stylesheets.LinkStyle;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;

@Data
public class Cart implements Serializable {
    private Double totalMoney;//总金额
    private Double saveMoney;//总金额
    private LinkedHashMap<Integer,CartItem> items = new LinkedHashMap<>();
    private int[] ids={};//购物车选中的购物车项

    public void sumMoney(){
        // 初始化金额
        double totalMoney = 0.0;
        double saveMoney = 0.0;
        if (!getItems().isEmpty()) {
            //计算勾选的购物车项的总价
            for (CartItem item : getItems().values()) {
                //如果item是勾选的进行计算
                if(item.isChecked()){
                    totalMoney += item.getJprice() * item.getCount();
                    saveMoney += (item.getPrice() - item.getJprice()) * item.getCount();
                }
            }
        }
        setTotalMoney(totalMoney);
        setSaveMoney(saveMoney);
    }
}